/*
* @Author: Administrator
* @Date:   2019-08-18 18:33:24
* @Last Modified by:   Administrator
* @Last Modified time: 2019-08-18 19:11:58
*/
const mongoose = require('mongoose');
var db = mongoose.connect('mongodb://localhost/movie', {useNewUrlParser: true});

var schema = new mongoose.Schema({name: String, age: Number, isAdult: Boolean});

schema.methods.say = function () {
	console.log( 'my name is ' + this.name +'，my age is ' + this.age );
}
var Student = mongoose.model('Student', schema);


var s1 = new Student({name: 'mark', age: 23, isAdult: false});

// s1.save(function (err, data) {
// 	console.log( data );
// 	data.say();
// });

console.log( 12 );
Student.find(function (error, result) {
	console.log( error );
	console.log( result );
	mongoose.disconnect();
});


// // Student.find({name: 'mark'}, {age: 1, '_id': 0},function (error, data) {
// // 	console.log( data );
// // })
// // // s1.say();

// var id = '5d592b08ae32062108d78a2a';

// Student.findById(id, function (error, data) {
// 	console.log( data );
// 	data.age= 45;
// 	data.save(function (error, data) {
// 		console.log( data );
// 		db.close();
// 	})
// })

// // Student.update({'_id':id}, {"$set": {age: 10}}, function (error, data) {
// // 	console.log( data );
// // })

// const query = Student.find(); // `query` 是 `Query` 的一个实例
// query.setOptions({ lean : true });
// query.collection(Student.collection);
// query.where('age').gte(11).limit(2).exec(function (error, data) {
// 	console.log( data );
// 	db.close();
// });


// // mongoose.disconnect();

